//
//  ILPastDaysTableViewController.m
//  ILife
//
//  Created by lanou on 15/10/29.
//  Copyright © 2015年 ILife. All rights reserved.
//

#import "ILPastDaysTableViewController.h"
#import <AFNetworking.h>
#import "ILDailySelectModel.h"
#import "ILDailySelectTableViewCell.h"
#import "ILDailySelectDetailViewController.h"

@interface ILPastDaysTableViewController ()
@property(nonatomic,strong)NSMutableArray *dataArr;



@end

@implementation ILPastDaysTableViewController

-(NSMutableArray *)dataArr
{
    if (_dataArr==nil) {
        self.dataArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArr;
    
    
}

-(NSString *)getUrlStr
{
    NSString *urlstr = [[@"http://baobab.wandoujia.com/api/v1/videos?strategy=date&categoryName=" stringByAppendingString:self.catagoryStr]stringByAppendingString:@"&num=10&vc=125&t=MjAxNTEwMjkxMDMzNDg5NjQsOTYwNA%3D%3D&u=aefb3e87a84d65c53a9cff2e3161dba6c3477f20&net=wifi&v=1.8.1&f=iphone"];
    return urlstr;
    
}
-(void)geteData
{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[self getUrlStr] parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
    
            for (NSDictionary *dict in responseObject[@"videoList"])
            {
                ILDailySelectModel *model = [[ILDailySelectModel alloc]init];
                [model setValuesForKeysWithDictionary:dict];
                [self.dataArr addObject:model];
            }
      
     
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        NSLog(@"error----%@",error);
    }];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self geteData];
    //设置Cell高度
    self.tableView.rowHeight = 777*SCREEN_WIDTH/1242;
    
    self.navigationItem.title = [self.catagoryStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self.tableView registerClass:[ILDailySelectTableViewCell class] forCellReuseIdentifier:@"past"];
    
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   ILDailySelectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"past" forIndexPath:indexPath];
    
    ILDailySelectModel *model = self.dataArr[indexPath.row];
    cell.dailySelectModel = model;
    
    
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ILDailySelectDetailViewController *detailVC = [[ILDailySelectDetailViewController alloc]init];
    
    detailVC.dataArr = self.dataArr;
    detailVC.index = indexPath.row;
    
//    [self.navigationController pushViewController:detailVC animated:YES];
    
    //#pragma 动画
    [UIView beginAnimations:nil context:NULL];
    [UIView  setAnimationDuration:0.7];
    [self.navigationController pushViewController:detailVC animated:YES];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];
    
    
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
